package com.sts.controller;

import com.sts.common.result.Result;
import com.sts.entity.Role;
import com.sts.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/roles")
@RequiredArgsConstructor
@PreAuthorize("hasRole('ADMIN')")
public class RoleController {
    private final RoleService roleService;
    @GetMapping
    public Result<List<Role>> list(){
        return Result.success(roleService.listAllRoles());
    }
    @PutMapping("/{id}/permissions")
    public Result<Void> assigenPerms(@PathVariable Long id,
                                     @RequestBody List<Long> permIds) {
        roleService.assignPerms(id, permIds);
        return Result.success().message("权限已分配");
    }
}
